package cn.icanci.loopstack.bic.biz.thread;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author icanci(1205068)
 * @version Id: ThreadUtils, v 0.1 2023/9/18 15:57 icanci Exp $
 */
public class ThreadUtils {
    /** 当前服务核心数 */
    private static final int                CORE_SIZE = Runtime.getRuntime().availableProcessors();
    /** 执行任务调度线程池 */
    private static final ThreadPoolExecutor POOL      = new ThreadPoolExecutor(CORE_SIZE,          //
        CORE_SIZE,                                                                                 //
        60L,                                                                                       //
        TimeUnit.SECONDS,                                                                          //
        new LinkedBlockingQueue<>(2000),                                                           //
        runnable -> new Thread(runnable, "ThreadUtils Biz Pool-" + runnable.hashCode()),           //
        (r, executor) -> {
            throw new RuntimeException("ThreadUtils Biz Pool is EXHAUSTED!");
        });

    /**
     * 线程执行
     *
     * @param command command
     */
    public static void execute(Runnable command) {
        POOL.execute(command);
    }
}
